package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderAdminService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/order")
@RestController("adminOrdersController")
@Slf4j
@Api(tags = "管理端订单接口")
public class OrdersController {

    @Autowired
    private OrderAdminService orderAdminService;
    /**
     * 管理端，订单搜索
     * @return
     */
    @ApiOperation("管理端，订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO dto){
        log.info("订单搜索：{}", dto);
        PageResult result = orderAdminService.page(dto);
        return Result.success(result);
    }

    /**
     * 统计
     * @return
     */
    @ApiOperation("统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("统计");
        OrderStatisticsVO vo = orderAdminService.statistics();
        return Result.success(vo);
    }

    /**
     * 订单详情
     * @return
     */
    @ApiOperation("订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
        log.info("订单详情{}",id);
        OrderVO vo =  orderAdminService.orderDetail(id);
        return Result.success(vo);
    }

    /**
     * 接单
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        log.info("接单{}",dto);
        orderAdminService.confirm(dto);
        return Result.success();
    }

    /**
     * 拒单
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result reject(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单{}",dto);
        orderAdminService.reject(dto);
        return Result.success();
    }


    /**
     * 取消订单
     *
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderAdminService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 派送订单
     *
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable("id") Long id) {
        orderAdminService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     *
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("id") Long id) {
        orderAdminService.complete(id);
        return Result.success();
    }

}
